package com.my.study.utils;

import org.apache.commons.io.IOUtils;

import java.io.FileInputStream;
import java.io.InputStream;

/**
 * @author: yidujun
 * @create: 2021/05/12 16:46
 */
public class IOUtil {

    public static String read(String path, String encoding) throws Exception {
        String content = null;

        InputStream inputStream = null;

        try {
            inputStream = IOUtil.class.getClassLoader().getResourceAsStream(path);
            if (inputStream == null) {
                // 从文件路径获取
                inputStream = new FileInputStream(path);
            }
            content = IOUtils.toString(inputStream, encoding);
        } finally {
            if (inputStream != null) {
                IOUtils.closeQuietly(inputStream);
            }
        }

        return content;
    }

}
